package com.sgb.kjwl.view.ui.adapter.home;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * 2021.04.01
 * 首页中商品界面的Tab页
 */
public class TabFragmentStateAdapter extends FragmentStateAdapter {
    private List<Fragment> fragmentArray;

    public TabFragmentStateAdapter(@NonNull FragmentActivity fragmentActivity, List<Fragment> fragmentArray) {
        super(fragmentActivity);
        if (fragmentArray == null) {
            this.fragmentArray = new ArrayList<>();
        } else {
            this.fragmentArray = fragmentArray;
        }
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return fragmentArray.get(position);
    }

    @Override
    public int getItemCount() {
        return fragmentArray.size();
    }
}
